﻿using System;
using System.Collections.Generic;
using System.Text;
using CGLib.Enums;

namespace CGLib
{
    public class Results
    {
        private int place = 0;
        private int turns = 0;

        /// <summary>
        /// The place the player is in. 0 if the player is still playing.
        /// </summary>
        public int Place
        {
            get { return place; }
            set { place = value; }
        }

        /// <summary>
        /// The number of turns the player has taken.
        /// </summary>
        public int Turns
        {
            get { return turns; }
            set { turns = value; }
        }

        /// <summary>
        /// Clear the results to its default values.
        /// </summary>
        public void ClearResults()
        {
            place = 0;
            turns = 0;
        }
    }

    public class Player
    {
        #region Fields

        private UserType usrType;
        private string name = string.Empty;
        private int number;
        private int cardsleft = 0;
        private IComputer ai;
        private string id;
        private Results results = new Results();
        private List<Card> cards = new List<Card>(13);
        private bool freeTurn;
        private bool skippedTurn;

        #endregion

        public Player(string Name, UserType type, int playernum, string ID)
        {
            name = Name;
            usrType = type;
            number = playernum;
            this.id = ID;
        }

        /// <summary>
        /// The type of user the player is.
        /// </summary>
        public UserType Type
        {
            get { return usrType; }
            set { usrType = value; }
        }

        /// <summary>
        /// The player number.
        /// </summary>
        public int Number
        {
            get { return number; }
            set { number = value; }
        }

        /// <summary>
        /// The number of cards the player has left.
        /// </summary>
        public int CardsLeft
        {
            get { return cardsleft; }
            set { cardsleft = value; }
        }

        /// <summary>
        /// The player's cards
        /// </summary>
        public List<Card> Cards
        {
            get { return cards; }
            set { cards = value; }
        }

        /// <summary>
        /// If it is the player's free turn.
        /// </summary>
        public bool FreeTurn
        {
            get { return freeTurn; }
            set { freeTurn = value; }
        }

        /// <summary>
        /// If the player has skipped his/her ending or previous turn.
        /// </summary>
        public bool SkippedTurn
        {
            get { return skippedTurn; }
            set { skippedTurn = value; }
        }

        /// <summary>
        /// [Online] The players MSN e-mail address, or AI ID.
        /// </summary>
        public string ID
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        /// The AI class. The player must be a computer player to use this.
        /// </summary>
        public IComputer AIFunc
        {
            get { return ai; }
            set { ai = value; }
        }

        /// <summary>
        /// The name of the player.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// The players current game results.
        /// </summary>
        public Results Results
        {
            get { return results; }
            set { results = value; }
        }

        /// <summary>
        /// [Online] Get if the player has left the game.
        /// </summary>
        /// <remarks>This is the shortcut to getting if the player has left, instead of using <see cref="Player.Type"/>.</remarks>
        public bool LeftGame
        {
            get { return Type == UserType.Leaver; }
        }
    }
}
